%%This file can draw pdr bargraph for small network and large network with different traffic load.
%% light traffic and heavy traffic
clc
close all
clear all

%the file @pdr_samples.mat should contain the following column vectors
% prks70, prks80, prks90, prks95
% prks_l70, prks_l80, prks_l90, prks_l95
% prks_r70, prks_r80, prks_r90, prks_r95
%
load pdr_samples.mat
ALPHA=0.05;

prks70 = 100 * prks70;
prks80 = 100 * prks80;
prks90 = 100 * prks90;
prks95 = 100 * prks95;
prks_l70 = 100 * prks_l70;
prks_l80 = 100 * prks_l80;
prks_l90 = 100 * prks_l90;
prks_l95 = 100 * prks_l95;
prks_r70 = 100 * prks_r70;
prks_r80 = 100 * prks_r80;
prks_r90 = 100 * prks_r90;
prks_r95 = 100 * prks_r95;

STD = zeros(4,3);
Error_STD = zeros(4,3);
STD(1,1) = std(prks70);
STD(1,2) = std(prks_r70);
STD(1,3) = std(prks_l70);
Error_STD(1,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks70) / sqrt(size(prks70, 1));
Error_STD(1,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks_r70) / sqrt(size(prks_r70, 1));
Error_STD(1,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks_l70) / sqrt(size(prks_l70, 1));

STD(2,1) = std(prks80);
STD(2,2) = std(prks_r80);
STD(2,3) = std(prks_l80);
Error_STD(2,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks80) / sqrt(size(prks80, 1));
Error_STD(2,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks_r80) / sqrt(size(prks_r80, 1));
Error_STD(2,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks_l80) / sqrt(size(prks_l80, 1));

STD(3,1) = std(prks90);
STD(3,2) = std(prks_r90);
STD(3,3) = std(prks_l90);
Error_STD(3,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks90) / sqrt(size(prks90, 1));
Error_STD(3,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks_r90) / sqrt(size(prks_r90, 1));
Error_STD(3,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks_l90) / sqrt(size(prks_l90, 1));

STD(4,1) = std(prks95);
STD(4,2) = std(prks_r95);
STD(4,3) = std(prks_l95);
Error_STD(4,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks95) / sqrt(size(prks95, 1));
Error_STD(4,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks_r95) / sqrt(size(prks_r95, 1));
Error_STD(4,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks_l95) / sqrt(size(prks_l95, 1));

figure;
handle = barweb(STD, Error_STD,1, ['70';'80';'90';'95'], [], ['PDR requirement(%)'], ['Mean standard deviation(%)'], jet);
handle.legend =legend ('PRKS','PRKS-R','PRKS-L','orientation','horizontal');
set(gca,'fontsize',20);
box on
maximize ();
saveas (gcf,'temp.fig');

%[im_hatch, colorlist]=applyhatch_pluscolor(gcf, '/-\xkc',1,[1 1 1 1 0 1],[],[],5,10);
